package com.edu.psychological_test.controller;

import com.edu.psychological_test.pojo.User;
import com.edu.psychological_test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    UserService userService;

    @PostMapping("/point")
    public String point(Model model, String username, String password, HttpServletRequest request){
        User user = userService.getUser(username, password);
        if (user == null){
            model.addAttribute("msg","密码错误");
            return "redirect:index";
        }
        request.getSession().setAttribute("user",user);

        return "redirect:main";
    }
//    @PostMapping("/getsession")
//    public Object getSession(HttpSession session){
//        if (session ==null){
//            return null;
//        }else {
//            Object user = session.getAttribute("user");
//            return user;
//        }
//    }

}
